C# HTML to PDF
HTML and PDF are both the hottest file format over the internet. HTML is necessary for most of websites and PDF is easy to share. In your projects you may need to convert HTML content to PDF for various reasons such as transfer, storage, print, etc. On the other hand, converting files from HTML to PDF format is one way of creating an electronic document that will display properly on any computer. So there are lots of HTML to PDF converters no matter free or commercial. Here in this article, I will share you another solution to convert HTML to PDF, C# HTML to PDF.
How to C# HTML to PDF
For developers, some professional .NET PDF components can help them easily convert HTML to PDF by using C#. Spire.PDF is one of them. With Spire.PDF, users can use C# to convert files from HTML to PDF effortlessly. Download Spire.PDF, make sure Spire.PDF and Visual Studio are correctly installed on system. Follow the simple instructions below to C# HTML to PDF.
Step 1 Create Project
Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. If your project is not in single thread, you need add [STAThread] before the main method.
using System;
using Spire.Pdf;
namespace HTMLtoPDF
{
class Program
{
[STAThread]
static void Main(string[] args)
{
}
}
}
Step 2 Create a PDF
We need create a blank PDF document in which we can convert HTML content in.
//Create a pdf document.
PdfDocument doc = new PdfDocument();
Step 3 C# HTML to PDF
We can directly convert HTML to PDF from link url.
String url = "http://www.e-iceblue.com";
doc.LoadFromHTML(url, false, true, true);
Step 4 Save and Preview
Save the output file as PDF format and preview it by using the following code:
//Save pdf file.
doc.SaveToFile("FromHTML.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("FromHTML.pdf");
Effective Screenshot:
How to C# HTML to PDF
For developers, some professional .NET PDF components can help them easily convert HTML to PDF by using C#. Spire.PDF is one of them. With Spire.PDF, users can use C# to convert files from HTML to PDF effortlessly. Download Spire.PDF, make sure Spire.PDF and Visual Studio are correctly installed on system. Follow the simple instructions below to C# HTML to PDF.
Step 1 Create Project
Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. If your project is not in single thread, you need add [STAThread] before the main method.
using System;
using Spire.Pdf;
namespace HTMLtoPDF
{
class Program
{
[STAThread]
static void Main(string[] args)
{
}
}
}
Step 2 Create a PDF
We need create a blank PDF document in which we can convert HTML content in.
//Create a pdf document.
PdfDocument doc = new PdfDocument();
Step 3 C# HTML to PDF
We can directly convert HTML to PDF from link url.
String url = "http://www.e-iceblue.com";
doc.LoadFromHTML(url, false, true, true);
Step 4 Save and Preview
Save the output file as PDF format and preview it by using the following code:
//Save pdf file.
doc.SaveToFile("FromHTML.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("FromHTML.pdf");
Effective Screenshot:
More about Spire.PDF
Spire.PDF can not only help developers Convert HTML to PDF via C#/VB.NET. As a PDF document creation component, Spire.PDF enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more…
Spire.PDF can not only help developers Convert HTML to PDF via C#/VB.NET. As a PDF document creation component, Spire.PDF enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more…